package com.celesea.workflow.core.entity;

import com.celesea.framework.authority.Dept;
import com.celesea.framework.authority.User;
import com.celesea.framework.entity.BusEntity;
import com.celesea.framework.util.EnvUtil;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import java.util.Calendar;
import java.util.Date;

/**
 * @author JackYuan
 * @create 2017-11-05 16:28
 */

public abstract class Workflow extends BusEntity {

    @Column(name = "`apply_id`", columnDefinition = "申请人Id", nullable = false, updatable = false)
    protected String applyId;
    @Column(name = "`apply_name`", columnDefinition = "申请人名称", nullable = false, updatable = false)
    protected String applyName;

    @Column(name = "`apply_dept_id`", columnDefinition = "申请人部门Id", nullable = false, updatable = false)
    protected String applyDeptId;
    @Column(name = "`apply_dept_name`", columnDefinition = "申请人部门名称", nullable = false, updatable = false)
    protected String applyDeptName;

    @Column(name = "`apply_time`", columnDefinition = "申请时间", nullable = false)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected Date applyTime;

    @Column(name = "`workflow_status`", columnDefinition = "工作流状态", nullable = false)
    protected Integer workflowStatus;


    public Workflow applyInfo() {
        User user = EnvUtil.getLoginUser();
        Dept dept = EnvUtil.getLoginDept();
        this.applyId = user.getId();
        this.applyName = user.getName();
        this.applyDeptId = dept.getId();
        this.applyDeptName = dept.getName();
        this.applyTime = Calendar.getInstance().getTime();
        this.workflowStatus = WorkflowStatus.DRAFT.getCode();
        return this;
    }


    public Workflow copyApplyInfo(Workflow model) {
        this.applyId = model.getApplyId();
        this.applyName = model.getApplyName();
        this.applyDeptId = model.getApplyDeptId();
        this.applyDeptName = model.getApplyDeptName();
        this.applyTime = model.getApplyTime();
        return this;
    }

    public String getApplyId() {
        return applyId;
    }

    public void setApplyId(String applyId) {
        this.applyId = applyId;
    }

    public String getApplyName() {
        return applyName;
    }

    public void setApplyName(String applyName) {
        this.applyName = applyName;
    }

    public String getApplyDeptId() {
        return applyDeptId;
    }

    public void setApplyDeptId(String applyDeptId) {
        this.applyDeptId = applyDeptId;
    }

    public String getApplyDeptName() {
        return applyDeptName;
    }

    public void setApplyDeptName(String applyDeptName) {
        this.applyDeptName = applyDeptName;
    }

    public Date getApplyTime() {
        return applyTime;
    }

    public void setApplyTime(Date applyTime) {
        this.applyTime = applyTime;
    }

    public Integer getWorkflowStatus() {
        return workflowStatus;
    }

    public void setWorkflowStatus(Integer workflowStatus) {
        this.workflowStatus = workflowStatus;
    }

}
